package com.pro.common.api.sitecontent.model.db;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.pro.common.api.CommonConst;
import com.pro.common.api.enums.init.EnumCurrency;
import com.pro.common.api.model.BaseConfigModel;
import com.pro.common.api.sitecontent.model.dto.CurrencyExchangeRateKey;
import com.pro.framework.javatodb.annotation.JTDTable;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;

@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "货币汇率")
@JTDTable(entityId = 311, sequences = {
        "UNIQUE KEY `uk_fromCurrency_toCurrency` (`from_currency`,`to_currency`)",
}, module = CommonConst.Modules.siteContent)
public class CurrencyExchangeRate extends BaseConfigModel {

    @Schema(description = "源货币代码（ISO 4217）")
    private EnumCurrency fromCurrency; // USD

    @Schema(description = "目标货币代码（ISO 4217）")
    private EnumCurrency toCurrency; // EUR

    @Schema(description = "汇率（1 源货币 = rate 目标货币）")
    private BigDecimal rate;

    @Schema(description = "汇率来源（可选）")
    private String source; // 手动配置, API等

     public CurrencyExchangeRateKey toKey() {
        return new CurrencyExchangeRateKey(fromCurrency, toCurrency);
    }
}
